package com.zzxy.spring34.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspectJ {

    @Pointcut(value = "execution(* com.zzxy.spring34.service.impl.*.*(..))")
    public void myPointcut(){

    }
    @Before("myPointcut()")
    public void myBefore(JoinPoint joinPoint){
        System.out.println("method interceptor : " +joinPoint.getSignature().getName());
        System.out.println("my before ....");
    }

    @After("myPointcut()")
    public void myAfter(JoinPoint joinPoint){
  //      System.out.println("method interceptor : " +joinPoint.getSignature().getName());
        System.out.println("my after ....");
    }
    @Around("myPointcut()")
    public Object myAround(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around before ..");
        Object obj = pjp.proceed();
        System.out.println("around after ..");
        return obj;
    }

    @AfterReturning(value = "myPointcut()",returning = "obj")
    public void myAfterReturning(JoinPoint joinPoint,Object obj){
        System.out.println("my after returning" + obj);
    }

    @AfterThrowing(value = "myPointcut()",throwing = "e")
    public void myThrowable(JoinPoint joinPoint,Throwable e){
        //biz
        //write to log file
        System.out.println("my throwable : " + e);

    }
}
